<template>
  <div class="no-padding app-container">
    <lst-page-container>
      <template slot="query">
        <el-form :model="tableQueryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
          <el-form-item label="整改状态" prop="repairState">
            <el-select v-model="tableQueryParams.repairState">
              <el-option
                  v-for="dict in dict.type.enum_question_repair"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </template>

      <template slot="rowHandel">
        <el-button type="primary" icon="el-icon-plus"
                   size="mini" @click="handleAdd">新增隐患
        </el-button>
      </template>

      <template slot="table">
        <el-table  @sort-change="handleSortChange"  height="100%" v-loading="loading" :data="dataList">
          <el-table-column :sortable="colum.sortable"  v-for="(colum,index) in questionTableColum" :key="index" :width="colum.width"
                           :label="colum.label"
                           :align="colum.align" :prop="colum.propValue">
            <template slot-scope="scope">
              <question-table-colum :scope="scope" :colum-config="colum"></question-table-colum>
            </template>
          </el-table-column>
          <el-table-column width="200" label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="showInfo(scope.row)"
              >查看
              </el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
              >修改
              </el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>

      <template slot="pageDisplay">
        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="tableQueryParams.pageNum"
            :limit.sync="tableQueryParams.pageSize"
            @pagination="getList"
        />
      </template>
    </lst-page-container>

    <el-drawer
        class="diy-draw"
        :title="title"
        :wrapperClosable="false"
        :visible.sync="open">
      <drawer-content>
        <template slot="body">
          <el-scrollbar>
            <el-form v-if="open" :rules="rules" :model="form" ref="form" size="small"
                     label-width="80px">
              <el-form-item class="column-item" label="隐患描述" prop="questionDesc">
                <el-input
                    v-model="form.questionDesc"
                    placeholder="请输入隐患描述"
                    type="textarea"
                    clearable
                >
                </el-input>
              </el-form-item>
              <el-form-item class="column-item " label="隐患分类" prop="questionTypeCode">
                <choose-question v-if="open" v-model="form.questionTypeCode"></choose-question>
              </el-form-item>
              <el-form-item class="column-item" label="整改建议" prop="suggestion">
                <el-input
                    v-model="form.suggestion"
                    placeholder="请输入整改建议"
                    type="textarea"
                    clearable
                >
                </el-input>
              </el-form-item>
              <el-form-item class="column-item annex-box" label="整改前附件" prop="fileIds">
                <template slot="label">
                  文件列表
                  <el-button class="file-upload-bt" icon="el-icon-refresh" size="mini"
                             @click="upload">上传文件
                  </el-button>
                </template>
                <show-file-list :file-list="fileList" @delFile="delFile"></show-file-list>
              </el-form-item>
            </el-form>
          </el-scrollbar>
        </template>
        <template slot="footer">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="submitData">确定</el-button>
        </template>
      </drawer-content>
    </el-drawer>


    <el-drawer
        class="diy-draw"
        title="隐患详情"
        :wrapperClosable="false"
        :size="HIDDEN_DANGER_WIDTH"
        :destroy-on-close="true"
        :visible.sync="infoOpen">
      <drawer-content>
        <template slot="body">
          <hidden-danger-info ref="danInfo" :info-data="infoData" :inspect-info="inspectInfo"></hidden-danger-info>
        </template>
      </drawer-content>
    </el-drawer>
  </div>
</template>

<script>
import {listPageMixins} from "@/mixins/listPageMixins";
import ShowFileList from "@/components/ShowFileList/index.vue";
import {isArr} from "@/utils/arrayUtil";
import {
  selfCheckAddQuestion,
  selfCheckQueryQuestion,
  selfCheckRemoveQuestion,
  selfCheckUpdateQuestion
} from "@/api/checkPage/selfCheck";
import {getQuestionDetail} from "@/api/checkPage/quertion";
import {subPageMixin} from "@/views/checkBusPage/mixins/subPageMixins";
import ChooseQuestion from "@/views/components/ChooseQuestion/index.vue";
import infoTable from "@/views/components/InfoTable/index.vue";
import HiddenDangerInfo from "@/views/checkBusPage/components/hiddenDangerInfo/index.vue";
import {HIDDEN_DANGER_WIDTH} from "@/constantData";

export default {
  mixins: [listPageMixins, subPageMixin],
  components: {
    ShowFileList,
    ChooseQuestion,
    infoTable,
    HiddenDangerInfo
  },
  dicts: ['enum_question_repair'],
  data() {
    return {
      HIDDEN_DANGER_WIDTH,
      modelName: '自查隐患',
      fileFiled:'fileVos',
      // 查询参数
      queryParams: {
        // 整改状态
        repairState: null,
        // 隐患类别
        questionTypeCode: null,
      },
      otherQueryParam: {
        inspectId: this.inspectInfo.id
      },
      getListFun: selfCheckQueryQuestion,
      addFun: selfCheckAddQuestion,
      updateFun: selfCheckUpdateQuestion,
      getInfoFun: getQuestionDetail,
      deleteFun: selfCheckRemoveQuestion,
      baseForm: {
        id: null,
        inspectId: this.inspectInfo.id,
        //  隐患描述
        questionDesc: null,
        //  隐患分类
        questionTypeCode: null,
        //  整改建议
        suggestion: null,
        //  整改前附件
        fileIds: [],
        fileVos:[]
      },
      rules: {
        questionDesc: [
          {required: true, message: "隐患描述不能为空", trigger: "blur"}
        ],
        questionTypeCode:[
          {required: true, message: "隐患分类不能为空", trigger: "change"}
        ]
      },
    }
  },
  watch: {
    fileList(val) {
      this.form.fileIds = isArr(val) ? val.map(file => file.fileId) : [];
    }
  },
}
</script>

<style scoped>

</style>
